import { EnumSchema } from '#/common';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 读写类型枚举 */
export enum ReadWriteTypeEnum {
  /** 读取 */
  Read = 1,
  /** 写入 */
  Write = 2,
}

/** 读写类型实体 */
export class ReadWriteTypeEntity {
  /** 读写类型 */
  ReadWrite: ReadWriteTypeEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(readWrite: ReadWriteTypeEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.ReadWrite = readWrite;
    this.Color = color;
    switch (readWrite) {
      case ReadWriteTypeEnum.Read:
        // this.Display = '读取';
        this.Display = t('iot.enum.readWriteType.read');
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case ReadWriteTypeEnum.Write:
        // this.Display = '写入';
        this.Display = t('iot.enum.readWriteType.write');
        this.Color = this.Color ? this.Color : PresetColorEnum.Orange;
        break;
    }
  }
}

//#region 获取读写类型枚举架构
/**
 * 获取读写类型枚举架构
 */
export function getReadWriteTypeEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: ReadWriteTypeEntity[] = [
    new ReadWriteTypeEntity(ReadWriteTypeEnum.Read),
    new ReadWriteTypeEntity(ReadWriteTypeEnum.Write),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.ReadWrite as number,
      label: item.Display,
      value: item.ReadWrite as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
